"use strict";

const { Controller } = require("egg");

class GroupController extends Controller {
  // 获取团购数据
  async getGroup() {
    const { ctx } = this;
    const { type, cities, countryCity, secondCity, value, state } = ctx.query;
    const list = await this.app.mysql.select("group");
    ctx.body = {
      code: 200,
      list: list
        .filter((item) => {
          if (
            cities == "省份" ||
            secondCity == "城市" ||
            countryCity == "县区"
          ) {
            return true;
          }
          return item.address.includes(cities);
        })
        .filter((item) => {
          if (
            cities == "省份" ||
            secondCity == "城市" ||
            countryCity == "县区"
          ) {
            return true;
          }
          return item.address.includes(secondCity);
        })
        .filter((item) => {
          if (
            cities == "省份" ||
            secondCity == "城市" ||
            countryCity == "县区"
          ) {
            return true;
          }
          return item.address.includes(countryCity);
        })
        .filter((v) => {
          if (state === "全部") return true;
          return v.state === state;
        })
        .filter((v) => {
          if (value == "") return true;
          return v.houses.includes(value);
        }),
    };
  }


}

module.exports = GroupController;
